<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>出库管理</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/dateUtil.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
.inputSize {
	width: 150px;
}
select{
	width: 150px;
	font-size: 12px;
}
td{
	font-size: 12px
}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		商品库存管理 &gt; 库存调拨
</div>

<form action="" method="post" >
<div id="searchbar">
<br>
	<table  style="width: 90%" border=0> 
		<tr>
			<td  width="13%">
      		调拨单号：
      		</td>
      		<td width="18%">
      			 <input id="transferNo" name="transferNo" type="text" value="${stockTransfer.transferNo}"  class="inputSize"/>
      		</td>
    		<td colspan="4"></td>
	    </tr>
	    <tr style="height: 9px">
     		<td colspan="8"></td>
    	</tr>
	    <tr>
			<td>
	     		调出仓库：
	     	</td>
	     	<td id = "whTd">
		     	 <select id="transferOutWhNo"  name="transferOutWhNo">
		            <option value="">请选择</option>
		            <c:forEach var="temp" items="${whareHouse}">
		            	<option value="${temp.whNo}" <c:if test="${stockTransfer.transferOutWhNo==temp.whNo}">selected="selected"</c:if>>${temp.whName}</option>
		            </c:forEach>
		        </select>
	        </td>
	  		<td>
	     		调入仓库：
	     	</td>
	     	<td id = "whTd">
		     	 <select id="transferInWhNo"  name="transferInWhNo">
		            <option value="">请选择</option>
		            <c:forEach var="temp" items="${whareHouse}">
		            	<option value="${temp.whNo}" <c:if test="${stockTransfer.transferInWhNo==temp.whNo}">selected="selected"</c:if>>${temp.whName}</option>
		            </c:forEach>
		        </select>
	        </td>
			<td colspan="4"></td>
 		</tr>
 		<tr style="height: 9px">
     		<td colspan="8"></td>
    	</tr>
 		<tr>
			<td>
	     		调出日期： 
	     	</td>
	     	<td>	
	     		<input style="width: 150px" id="beginTime" type="text" name="beginTransferOutTime" readonly="readonly" value="${stockTransfer.beginTransferOutTime}" class="Wdate" value="" size="21"
	    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'endTime\')||\'2020-10-01\'}'})" >
			</td>
			<td>
				至
			</td>
			<td>
			<input style="width: 150px" id="endTime" type="text" name="endTransferOutTime" readonly="readonly" value="${stockTransfer.endTransferOutTime}" class="Wdate" value="" size="21"
	    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'beginTime\')||\'2013-01-01\'}'})" >
			</td>
			<td colspan="2">
	  		</td>
  		</tr>
  		<tr style="height: 9px">
     		<td colspan="8"></td>
    	</tr>
  		<tr>
			<td>
	     		调入日期： 
	     	</td>
	     	<td>	
	     		<input style="width: 150px" id="beginTime" type="text" name="beginTransferInTime" readonly="readonly" value="${stockTransfer.beginTransferInTime}" class="Wdate" value="" size="21"
	    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'endTime\')||\'2020-10-01\'}'})" >
			</td>
			<td>
				至
			</td>
			<td>
			<input style="width: 150px" id="endTime" type="text" name="endTransferInTime" readonly="readonly" value="${stockTransfer.endTransferInTime}" class="Wdate" value="" size="21"
	    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'beginTime\')||\'2013-01-01\'}'})" >
			</td>
			<td colspan="2">
			   <input id="btnOK" type="submit" value="查询" class="l-button-search" />
	           <input type="button" id="resetBtn" value="重置" class="l-button-search" />
	  		</td>
  		</tr>
	</table>
</div>
</form>

<div id="dataGrid" style="margin:0; padding:0"></div>
<script>
    var basePath='${BasePath}';
	var tabId = window.top.tab.getSelectedTabItemID();
    var grid = null;
    $(function () {
   	 	var roles = new Array();
   	    var role = false
   	    '<c:forEach items="${roleVos}" var="item">';
   	   		roles.push('${item.roleCode}');
   	    '</c:forEach>';
   	 	for ( var i in roles) {
   	 		if( roles[i] == 'WAREHOUSE_SUPERVISOR' || roles[i] == 'SYSTEM_ADMIN'){
   	 			role = true;
   	 			break;
   	 		}
   	 	}
    	 // 重置
        $("#resetBtn").click(function(){
    		$('#searchbar :input').not(':submit, :button, :reset').val('').removeAttr('checked').removeAttr('selected');
    	});
    	 
        grid = $("#dataGrid").ligerGrid({
            columns: [
            { display: '调拨编号', name: 'transferNo'},
            { display: '调出仓库', name: 'transferOutWhName'},
            { display: '调入仓库', name: 'transferInWhName'},
            { display: '负责人', name: 'director'},
            { display: '创建日期', name: 'createTime',render: function(rowdata, rowindex, value){
     		   	if(value == '' || value == null){
     				return  "";
     			}
     		   	value = getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
     			return value
     		}},
            { display: '当前状态', name: 'flowState',render:function(rowdata,rowindex,value){
            	if(parseInt(value) == 0){
                 	return "待审核";
                }else if(parseInt(value) == 1){
                	 return "待生成出库单 ";
                }else if(parseInt(value) == 2){
                	 return "已生成出库单";
                }else if(parseInt(value) == 3){
                	 return "待生成入库单";
                }else if(parseInt(value) == 4){
                	 return "已生成入库单";
                }else if(parseInt(value) == 5){
                	 return "调拨完成";
                }
            	return "";
            }},
            { display: '审核人', name: 'auditor'},
            { display: '审核日期', name: 'approveTime',render: function(rowdata, rowindex, value){
     		   	if(value == '' || value == null){
     				return  "";
     			}
     		   	value = getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
     			return value
     		}},
            { display: '调出日期', name: 'transferOutTime',render: function(rowdata, rowindex, value){
     		   	if(value == '' || value == null){
     				return  "";
     			}
     		   	value = getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
     			return value
     		}},
     		{ display: '调入日期', name: 'transferInTime',render: function(rowdata, rowindex, value){
     		   	if(value == '' || value == null){
     				return  "";
     			}
     		   	value = getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
     			return value
     		}},
     		/* { display: '备注', name: 'remark'}, */
            { display: '操作',width:150, name: 'flowState', isSort: false, render: function (rowdata, rowindex, value){
            	var text = "";
            	if(value == 0 && role == true){
            		text += "<a id = 'operate1' href='javascript:deleteStockTransfer(" + rowindex + ")'>废除</a>&nbsp;&nbsp;";
            		text += "<a id = 'operate2' href='javascript:approveStockTransfer(" + rowindex + ")'>审核</a>&nbsp;&nbsp;";
            	}else if(value == 1){
            		text += "<a id = 'operate1' href='javascript:createStockOutBill(" + rowindex + ")'>生成出库单</a>&nbsp;&nbsp;";
            	}else if(value == 3){
            		text += "<a id = 'operate1' href='javascript:createStockInBill(" + rowindex + ")'>生成入库单</a>&nbsp;&nbsp;";
            	}
            	text += "<a id = 'operate3' href='javascript:queryStockTransfer(" + rowindex + ")'>详情</a>&nbsp;&nbsp;";
            	return text;
            }},
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
				{name: "transferNo", value:$("#transferNo").val()},
				{name: "transferOutWhNo", value:$("#transferOutWhNo").val()},
				{name: "transferInWhNo", value:$("#transferInWhNo").val()},
				{name: "beginTransferOutTime", value : getFullTime($("input[name=beginTransferOutTime]").val(),true)},
				{name: "endTransferOutTime", value : getFullTime($("input[name=endTransferOutTime]").val(),false)},
				{name: "beginTransferInTime", value : getFullTime($("input[name=beginTransferInTime]").val(),true)},
				{name: "endTransferInTime", value : getFullTime($("input[name=endTransferInTime]").val(),false)}
             ],
             url: "ajaxPageFinderStockTransfer.do",
             toolbar: {items: [{ text: "新增", click: queryStockTransfer2, icon: "add" },{line: true}]}		
        });
    });
    
    function queryStockTransfer2(index){
		var url= basePath + '/warehouse/stockTransferController/toAddStockTransfer.do?tabId='+ tabId;
		window.parent.f_addTab('新增调拨','新增调拨',url);
    }
    
    function queryStockTransfer(index){
    	var id = grid.getData()[index].id;
		var url= basePath + '/warehouse/stockTransferController/toStockTransferDetail.do?tabId='+ tabId +'&id='+id;
		window.parent.f_addTab('调拨详情','调拨详情',url);
    }
    
    
    function deleteStockTransfer(index) {
		var id = grid.getData()[index].id;
		$.ligerDialog.confirm('确定废除该数据？',
		function(yes) {
			if (yes) {
				$.post(
					basePath + '/warehouse/stockTransferController/deleteStockTransfer.do',
 					{id : id},
 					function(data) {
 						if (data == 'success') {
 							grid.loadData(); 
 							window.parent.parent.f_tip('删除成功');
 						} else if (data == 'fail') {
 							window.parent.parent.f_tip('删除失败');
 						}
 					}
				);
			};
		});
	 }
    
    function approveStockTransfer(index) {
		var transferNo = grid.getData()[index].transferNo;
		$.ligerDialog.confirm('是否确认通过该调拨单？',
		function(yes) {
			if (yes) {
				$.post(
					basePath + '/warehouse/stockTransferController/approveStockTransfer.do',
 					{transferNo : transferNo},
 					function(data) {
 						if (data == 'success') {
 							grid.loadData(); 
 							window.parent.parent.f_tip('确认成功');
 						} else if (data == 'fail') {
 							window.parent.parent.f_tip('确认失败');
 						}
 					}
				);
			};
		});
	 }
    
     function createStockOutBill(index){
    	 var rowData =  grid.getData()[index];
    	 var url = '${BasePath}/stockmanage/StockController/toTransferStockOut.do?tabId='+ tabId + '&transferNo='+rowData.transferNo +'&transferInWhNo='+ rowData.transferInWhNo +'&transferOutWhNo='+ rowData.transferOutWhNo+'&transferOutWhName='+ rowData.transferOutWhName;
    	 window.parent.f_addTab('生成调拨出库单','生成调拨出库单',url);
     }
     
     function createStockInBill(index){
    	 var rowData =  grid.getData()[index];
    	 var url = '${BasePath}/stockmanage/StockController/toTransferStockIn.do?tabId='+ tabId + '&transferNo='+rowData.transferNo +'&transferInWhNo='+ rowData.transferInWhNo +'&transferInWhName='+ rowData.transferInWhName;
    	 window.parent.f_addTab('生成调拨入库单','生成调拨入库单',url);
     }
</script>
</body>
</html>